﻿using Microsoft.AspNetCore.Razor.TagHelpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace _17bang.TagHelpers
{
    [HtmlTargetElement("datetime", Attributes = "asp-showicon,asp-only")]
    public class DateTimeTagHelper : TagHelper
    {
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            output.TagName = "small";
            if (context.AllAttributes["asp-showicon"].Value.ToString() == "true")
            {
                output.GetChildContentAsync().Result.GetContent();
                output.PreContent.SetHtmlContent("<span class=\"fa fa - calendar\"></span>");
            }//elsenothing

            if (context.AllAttributes["asp-only"].Value.ToString() == "date")
            {
                output.Content.SetHtmlContent(Convert.ToDateTime(output.GetChildContentAsync().Result.GetContent()).ToString("yyyy年MM月dd日"));

            }//elsenothing
            base.Process(context, output);
        }
    }

}
